package com.mmw.crm.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mmw.crm.bo.ReceivablesPageVo;
import com.mmw.crm.entity.Receivables;
import com.mmw.crm.result.Result;
import com.mmw.crm.service.ReceivablesService;
import com.mmw.crm.vo.CustomerVo;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ReceivablesController {

    @Resource
    ReceivablesService receivablesService;

    @PostMapping("CrmReceivables/queryPageList")
    public Result crmReceivablesQueryPageList(@RequestBody CustomerVo customerVo){
        Integer page = customerVo.getPage();
        Integer limit = customerVo.getLimit();
        String search = customerVo.getSearch();

        LambdaQueryWrapper<Receivables> wrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(wrapper)){
            wrapper.like(Receivables::getNumber,search);
        }
        Page<Receivables> pageInfo = new Page<>(page,limit);
        receivablesService.page(pageInfo,wrapper);

        List<Receivables> records = pageInfo.getRecords();
        ReceivablesPageVo receivablesPageVo = new ReceivablesPageVo();
        receivablesPageVo.setList(records);
        receivablesPageVo.setTotalRow(records.size());

        return Result.build(receivablesPageVo,null,0);
    }
    @PostMapping("CrmReceivables/deleteByIds")
    public Result crmBusinessDeleteByIds(@RequestParam List<Integer> receivablesIds){
        receivablesService.removeByIds(receivablesIds);
        return Result.build(null,null,0);
    }
}
